home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / util / misc / Fudgit233.lha / Source / src / readline2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-14  |  3.4 KB  |  140 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <sys/types.h>
  4. #include <sys/file.h>
  5. #include <sys/stat.h>
  6. #include <sys/errno.h>
  7. #include "readline/readline.h"
  8. #include "readline/history.h"
  9.  
  10. #include "fudgit.h"
  11. #include "command.h"
  12. #include "macro.h"
  13. #include "head.h"
  14.  
  15. static char **fudgit_completion(char *text, int start, int end);
  16. static char *com_generator(char *text, int state);
  17.  
  18. extern void *malloc (size_t);
  19.  
  20. int Ft_initreadline(void)
  21. {
  22.     char buffer[512];
  23.     extern char Ft_Home[];
  24.  
  25.     rl_readline_name = "Fudgit";
  26.     rl_attempted_completion_function = (UFunction *)fudgit_completion;
  27.     hl_using_history();
  28.     sprintf(buffer, "%s/%s", Ft_Home, HISTORY);
  29.     hl_read_history(buffer);
  30.     hl_stifle_history(HISTNUM);
  31.     return(0);
  32. }
  33.  
  34. static char **fudgit_completion(char *text, int start, int end)
  35. {
  36.     char **matches;
  37.     extern char *Ft_var_generator(char *text, int state);
  38.     extern char *username_completion_function();
  39.     extern char *rl_line_buffer;
  40.     extern int Ft_Mode;
  41.  
  42.     matches = (char **)NULL;
  43.     if (Ft_Mode == CMODE) {
  44.         matches = completion_matches(text, Ft_var_generator);
  45.     }
  46.     else {
  47.         if (start == 0)
  48.             matches = completion_matches(text, com_generator);
  49.         else if (rl_line_buffer[start-1] == '$')
  50.             matches = completion_matches(text, Ft_var_generator);
  51.         /********************
  52.         else if (rl_line_buffer[start] == '~')
  53.             matches = completion_matches(text, username_completion_function);
  54.         else
  55.             matches = completion_matches(text, arg_generator);
  56.         ********************/
  57.     }
  58.     return(matches);
  59. }
  60.  
  61. static char *com_generator(char *text, int state)
  62. {
  63.     static int list_index2, len, done1;
  64.     register char *name, *cp;
  65.     register Macro *mpp;
  66.     static Macro *mp;
  67.     extern Command Ft_Cmds[];
  68.     extern Macro *Ft_mplisp(void);
  69.  
  70.     if (!state) {
  71.         list_index2 = 0;
  72.         done1 = 0;
  73.         mp = Ft_mplisp();
  74.         len = strlen(text);
  75.     }
  76.     if (!done1) { /* search for aliases */
  77.         while (mp) {
  78.             mpp = mp;
  79.             mp = mp->next;
  80.             if (mpp->type != ANALIAS && mpp->type != AMACRO)
  81.                 continue;
  82.             name = mpp->fname;
  83.                if (strncmp(name, text, len) == 0) {
  84.                    cp = (char *)malloc(strlen(name) + 1);
  85.                    strcpy(cp, name);
  86.                    return(cp);
  87.                }
  88.         }
  89.         done1 = 1;
  90.     }
  91.     while ((name = Ft_Cmds[list_index2].fname)) {
  92.            list_index2++;
  93.            if (strncmp(name, text, len) == 0) {
  94.                cp = (char *)malloc(strlen(name) + 1);
  95.                strcpy(cp, name);
  96.                return(cp);
  97.            }
  98.     }
  99.     return((char  *)NULL);
  100. }
  101.  
  102. /***************************************
  103. char *arg_generator(text, state)
  104. char *text;
  105. int state;
  106. {
  107.     static int list_index1, list_index2, len;
  108.     char *name, *cp;
  109.     extern Command Shows[], Sets[];
  110.  
  111.     if (!state) {
  112.         list_index1 = list_index2 = 0;
  113.         len = strlen(text);
  114.     }
  115.     while (name = Sets[list_index1].fname) {
  116.         list_index1++;
  117.         while (*name != ' ' && *name != '\0')
  118.             name++;
  119.         name++;
  120.         if (strncmp(name, text, len) == 0) {
  121.             cp = (char *)malloc(strlen(name) + 1);
  122.             strcpy(cp, name);
  123.             return(cp);
  124.         }
  125.     }
  126.     while (name = Shows[list_index2].fname) {
  127.         list_index2++;
  128.         while (*name != ' ' && *name != '\0')
  129.             name++;
  130.         name++;
  131.         if (strncmp(name, text, len) == 0) {
  132.             cp = (char *)malloc(strlen(name) + 1);
  133.             strcpy(cp, name);
  134.             return(cp);
  135.         }
  136.     }
  137.     return(NULL);
  138. }
  139. **********************/
  140.